package com.employ.job.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.employ.common.utils.uuid.IdUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.employ.common.annotation.Log;
import com.employ.common.core.controller.BaseController;
import com.employ.common.core.domain.AjaxResult;
import com.employ.common.enums.BusinessType;
import com.employ.job.domain.EmpCompanies;
import com.employ.job.service.IEmpCompaniesService;
import com.employ.common.utils.poi.ExcelUtil;
import com.employ.common.core.page.TableDataInfo;

/**
 * 企业Controller
 *
 * @author ruoyi
 * @date 2025-02-24
 */
@RestController
@RequestMapping("/job/companies")
public class EmpCompaniesController extends BaseController
{
    @Autowired
    private IEmpCompaniesService empCompaniesService;

    /**
     * 查询企业列表
     */
    @PreAuthorize("@ss.hasPermi('job:companies:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmpCompanies empCompanies)
    {
        startPage();
        List<EmpCompanies> list = empCompaniesService.selectEmpCompaniesList(empCompanies);
        return getDataTable(list);
    }

    /**
     * 查询企业列表
     */
    @PreAuthorize("@ss.hasPermi('job:companies:list')")
    @GetMapping("/companyList")
    public AjaxResult companyList(EmpCompanies empCompanies)
    {
        List<EmpCompanies> list = empCompaniesService.selectEmpCompaniesList(empCompanies);
        return success(list);
    }

    /**
     * 导出企业列表
     */
    @PreAuthorize("@ss.hasPermi('job:companies:export')")
    @Log(title = "企业", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmpCompanies empCompanies)
    {
        List<EmpCompanies> list = empCompaniesService.selectEmpCompaniesList(empCompanies);
        ExcelUtil<EmpCompanies> util = new ExcelUtil<EmpCompanies>(EmpCompanies.class);
        util.exportExcel(response, list, "企业数据");
    }

    /**
     * 获取企业详细信息
     */
    @PreAuthorize("@ss.hasPermi('job:companies:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(empCompaniesService.selectEmpCompaniesById(id));
    }

    /**
     * 新增企业
     */
    @PreAuthorize("@ss.hasPermi('job:companies:add')")
    @Log(title = "企业", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmpCompanies empCompanies)
    {
        empCompanies.setId(IdUtils.fastSimpleUUID());
        return toAjax(empCompaniesService.insertEmpCompanies(empCompanies));
    }

    /**
     * 修改企业
     */
    @PreAuthorize("@ss.hasPermi('job:companies:edit')")
    @Log(title = "企业", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmpCompanies empCompanies)
    {
        return toAjax(empCompaniesService.updateEmpCompanies(empCompanies));
    }

    /**
     * 删除企业
     */
    @PreAuthorize("@ss.hasPermi('job:companies:remove')")
    @Log(title = "企业", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(empCompaniesService.deleteEmpCompaniesByIds(ids));
    }
}
